package com.leetcode.p200;

public class Test279_2 {

    public int numSquares(int n) {
        int[] dp = new int[n + 1];

        for (int i = 1; i <= n; i++) {
            dp[i] = i;
            for (int j = 0; i - j * j >= 0; j++) {
                dp[i] = Math.min(dp[i], dp[i - j * j] + 1);
            }
        }
        return dp[n];
    }

    public static void main(String[] args) {

        Test279_2 test = new Test279_2();
//        int result = test.numSquares(12);
        int result = test.numSquares(12);
        System.out.println(result);
    }

}
